public class MyBlockingQueue {
    private int[] arr = new int[100];
    private int head = 0;
    private int tail = 0;
    private int size = 0;

    public void put(int val) throws InterruptedException {
        synchronized (this) {
            if(size == arr.length){
                wait();
            }
            arr[tail++] = val;
            if(tail >= arr.length){
                tail = 0;
            }
            size++;
            notify();
        }
    }

    public int take() throws InterruptedException {
        synchronized (this) {
            if(size == 0){
                wait();
            }
            int ret = arr[head];
            head++;
            if(head >= arr.length){
                head = 0;
            }
            size--;
            notify();
            return ret;
        }
    }

    public int size(){
        synchronized (this) {
            return size();
        }
    }
}
